<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InkType">


    <Style TargetType="{x:Type local:LabelledControl}">
        <Setter Property="Margin" Value="6 2"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:LabelledControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="LabelledControl"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBlock Text="{TemplateBinding Label}" Margin="6,0,3,0" VerticalAlignment="Center" TextAlignment="Right"/>
                        <ContentPresenter Grid.Column="1"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:SlideInOutControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:SlideInOutControl}">
                    <ContentPresenter x:Name="p" Content="{TemplateBinding Content}">
                        <FrameworkElement.RenderTransform>
                            <TranslateTransform>
                                <TranslateTransform.X>
                                    <MultiBinding Converter="{x:Static local:SlideInOutControl.HAmountConverter}">
                                        <Binding Path="Dock" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="Completion" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="ActualWidth" ElementName="p"/>
                                    </MultiBinding>
                                </TranslateTransform.X>
                                <TranslateTransform.Y>
                                    <MultiBinding Converter="{x:Static local:SlideInOutControl.VAmountConverter}">
                                        <Binding Path="Dock" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="Completion" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="ActualHeight" ElementName="p"/>
                                    </MultiBinding>
                                </TranslateTransform.Y>
                            </TranslateTransform>
                        </FrameworkElement.RenderTransform>
                    </ContentPresenter>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:FlipControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:FlipControl}">
                    <Grid>
                        <local:SlideInOutControl x:Name="front" Dock="Bottom">
                            <ContentPresenter Content="{TemplateBinding Content}"/>
                        </local:SlideInOutControl>
                        <local:SlideInOutControl x:Name="back" Dock="Top" Visibility="Collapsed">
                            <ContentPresenter Content="{TemplateBinding FlipContent}"/>
                        </local:SlideInOutControl>
                    </Grid>
                    <ControlTemplate.Resources>
                        <Duration x:Key="flipDuration">0:0:0.3</Duration>
                        <ExponentialEase x:Key="easeFunc" EasingMode="EaseOut" Exponent="3"/>
                    </ControlTemplate.Resources>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsFlipped" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="back" Storyboard.TargetProperty="Visibility" Duration="{StaticResource flipDuration}">
                                            <DiscreteObjectKeyFrame KeyTime="0%" Value="{local:Enum {x:Type Visibility}, Visible}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="front" Storyboard.TargetProperty="Visibility" Duration="{StaticResource flipDuration}">
                                            <DiscreteObjectKeyFrame KeyTime="100%" Value="{local:Enum {x:Type Visibility}, Collapsed}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Storyboard.TargetName="back" Storyboard.TargetProperty="Completion" To="0" Duration="{StaticResource flipDuration}" EasingFunction="{StaticResource easeFunc}"/>
                                        <DoubleAnimation Storyboard.TargetName="front" Storyboard.TargetProperty="Completion" To="1" Duration="{StaticResource flipDuration}" EasingFunction="{StaticResource easeFunc}"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="back" Storyboard.TargetProperty="Visibility" Duration="{StaticResource flipDuration}">
                                            <DiscreteObjectKeyFrame KeyTime="100%" Value="{local:Enum {x:Type Visibility}, Collapsed}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="front" Storyboard.TargetProperty="Visibility" Duration="{StaticResource flipDuration}">
                                            <DiscreteObjectKeyFrame KeyTime="0%" Value="{local:Enum {x:Type Visibility}, Visible}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation Storyboard.TargetName="back" Storyboard.TargetProperty="Completion" To="1" Duration="{StaticResource flipDuration}" EasingFunction="{StaticResource easeFunc}"/>
                                        <DoubleAnimation Storyboard.TargetName="front" Storyboard.TargetProperty="Completion" To="0" Duration="{StaticResource flipDuration}" EasingFunction="{StaticResource easeFunc}"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
